﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class StepManager_SY2 : MonoBehaviour
{
    public Text[] StepOneNames;
    public Text[] StepTwoNames;
    public Text[] StepThreeNames;
    public Text[] StepFourNames;
    public Text[] StepFiveNames;

    public Text[] BigStepNames;
    public Button[] BigStepButtons;

    public GameObject demo;
    public GameObject self;

    [HideInInspector]
    public int m_Score;

    [HideInInspector]
    public bool[] StepOneNum = new bool[5];//记录检查道具步骤
    [HideInInspector]
    public bool[] StepTwoNum = new bool[4];//记录实验步骤2步骤
    [HideInInspector]
    public bool[] StepThreeNum = new bool[3];//记录实验步骤3步骤
    [HideInInspector]
    public bool[] StepFourNum = new bool[2];//记录实验步骤4
    [HideInInspector]
    public bool[] StepFiveNum = new bool[3];//记录实验步骤3步骤

    List<string> SmallSteps;

    public List<string> GetSmallSteps()
    {
        SmallSteps.Clear();
        for (int i = 0; i < StepOneNum.Length; i++)
        {
            SmallSteps.Add(StepOneNum[i].ToString());
        }
        for (int i = 0; i < StepTwoNum.Length; i++)
        {
            SmallSteps.Add(StepTwoNum[i].ToString());
        }
        for (int i = 0; i < StepThreeNum.Length; i++)
        {
            SmallSteps.Add(StepThreeNum[i].ToString());
        }
        for (int i = 0; i < StepFourNum.Length; i++)
        {
            SmallSteps.Add(StepFourNum[i].ToString());
        }
        for (int i = 0; i < StepFiveNum.Length; i++)
        {
            SmallSteps.Add(StepFiveNum[i].ToString());
        }
        return SmallSteps;
    }

    private int stepOneScore;
    private int stepTwoScore;
    private int stepThreeScore;
    private int stepFourScore;
    private int stepFiveScore;

    public static StepManager_SY2 Instance;

    private void Awake()
    {
        Instance = this;
    }


    public void ResetText()
    {
        for (int i = 0; i < StepOneNames.Length; i++)
        {
            StepOneNames[i].color = Color.black;
        }
        for (int i = 0; i < StepTwoNames.Length; i++)
        {
            StepTwoNames[i].color = Color.black;
        }
        for (int i = 0; i < StepThreeNames.Length; i++)
        {
            StepThreeNames[i].color = Color.black;
        }
        for (int i = 0; i < StepFourNames.Length; i++)
        {
            StepFourNames[i].color = Color.black;
        }
        for (int i = 0; i < StepFiveNames.Length; i++)
        {
            StepFiveNames[i].color = Color.black;
        }
    }

    public void ResetText(int step)
    {
        switch (step)
        {
            case 2:
                for (int i = 0; i < StepTwoNames.Length; i++)
                {
                    StepTwoNames[i].color = Color.black;
                }
                for (int i = 0; i < StepThreeNames.Length; i++)
                {
                    StepThreeNames[i].color = Color.black;
                }
                for (int i = 0; i < StepFourNames.Length; i++)
                {
                    StepFourNames[i].color = Color.black;
                }
                for (int i = 0; i < StepFiveNames.Length; i++)
                {
                    StepFiveNames[i].color = Color.black;
                }
                BigStepNames[0].color = Color.black;
                BigStepNames[1].color = Color.black;
                BigStepNames[2].color = Color.black;
                BigStepNames[3].color = Color.black;
                BigStepButtons[0].enabled = false;
                BigStepButtons[1].enabled = false;
                BigStepButtons[2].enabled = false;
                BigStepButtons[3].enabled = false;
                break;
            case 3:
                for (int i = 0; i < StepThreeNames.Length; i++)
                {
                    StepThreeNames[i].color = Color.black;
                }
                for (int i = 0; i < StepFourNames.Length; i++)
                {
                    StepFourNames[i].color = Color.black;
                }
                for (int i = 0; i < StepFiveNames.Length; i++)
                {
                    StepFiveNames[i].color = Color.black;
                }
                BigStepNames[1].color = Color.black;
                BigStepNames[2].color = Color.black;
                BigStepNames[3].color = Color.black;
                BigStepButtons[0].enabled = true;
                BigStepButtons[1].enabled = false;
                BigStepButtons[2].enabled = false;
                BigStepButtons[3].enabled = false;
                break;
            case 4:
                for (int i = 0; i < StepFourNames.Length; i++)
                {
                    StepFourNames[i].color = Color.black;
                }
                for (int i = 0; i < StepFiveNames.Length; i++)
                {
                    StepFiveNames[i].color = Color.black;
                }
                BigStepNames[2].color = Color.black;
                BigStepNames[3].color = Color.black;
                BigStepButtons[0].enabled = true;
                BigStepButtons[1].enabled = true;
                BigStepButtons[2].enabled = false;
                BigStepButtons[3].enabled = false;
                break;
            case 5:
                for (int i = 0; i < StepFiveNames.Length; i++)
                {
                    StepFiveNames[i].color = Color.black;
                }
                BigStepNames[3].color = Color.black;
                BigStepButtons[0].enabled = true;
                BigStepButtons[1].enabled = true;
                BigStepButtons[2].enabled = true;
                BigStepButtons[3].enabled = false;
                break;
        }
    }

    public void ResetData(int step)
    {
        switch (step)
        {
            case 1:
                for (int i = 0; i < StepOneNum.Length; i++)
                {
                    StepOneNum[i] = false;
                }
                for (int i = 0; i < StepTwoNum.Length; i++)
                {
                    StepTwoNum[i] = false;
                }
                for (int i = 0; i < StepThreeNum.Length; i++)
                {
                    StepThreeNum[i] = false;
                }
                for (int i = 0; i < StepFourNames.Length; i++)
                {
                    StepFourNum[i] = false;
                }
                for (int i = 0; i < StepFiveNum.Length; i++)
                {
                    StepFiveNum[i] = false;
                }
                break;
            case 2:
                for (int i = 0; i < StepTwoNum.Length; i++)
                {
                    StepTwoNum[i] = false;
                }
                for (int i = 0; i < StepThreeNum.Length; i++)
                {
                    StepThreeNum[i] = false;
                }
                for (int i = 0; i < StepFourNames.Length; i++)
                {
                    StepFourNum[i] = false;
                }
                for (int i = 0; i < StepFiveNum.Length; i++)
                {
                    StepFiveNum[i] = false;
                }
                break;
            case 3:
                for (int i = 0; i < StepThreeNum.Length; i++)
                {
                    StepThreeNum[i] = false;
                }
                for (int i = 0; i < StepFourNames.Length; i++)
                {
                    StepFourNum[i] = false;
                }
                for (int i = 0; i < StepFiveNum.Length; i++)
                {
                    StepFiveNum[i] = false;
                }
                break;
            case 4:
                for (int i = 0; i < StepFourNames.Length; i++)
                {
                    StepFourNum[i] = false;
                }
                for (int i = 0; i < StepFiveNum.Length; i++)
                {
                    StepFiveNum[i] = false;
                }
                break;
            case 5:
                for (int i = 0; i < StepFiveNum.Length; i++)
                {
                    StepFiveNum[i] = false;
                }
                break;
        }
    }

    public void SetScore()
    {
        m_Score = stepOneScore + stepTwoScore + stepThreeScore + stepFourScore + stepFiveScore;
        GameObject.Find("scoreText").GetComponent<Text>().text = m_Score + "";
    }

    public void ResetScore()
    {
        stepOneScore = 0;
        stepTwoScore = 0;
        stepThreeScore = 0;
        stepFourScore = 0;
        stepFiveScore = 0;
    }

    public void ResetScore(int step)
    {
        switch (step)
        {
            case 1:
                stepOneScore = 0;
                stepTwoScore = 0;
                stepThreeScore = 0;
                stepFourScore = 0;
                stepFiveScore = 0;
                break;
            case 2:
                stepTwoScore = 0;
                stepThreeScore = 0;
                stepFourScore = 0;
                stepFiveScore = 0;
                break;
            case 3:
                stepThreeScore = 0;
                stepFourScore = 0;
                stepFiveScore = 0;
                break;
            case 4:
                stepFourScore = 0;
                stepFiveScore = 0;
                break;
            case 5:
                stepFiveScore = 0;
                break;
        }
        SetScore();
    }

    public const int needCheckNum = 8;//需要检查的道具总个数


    public void SetStepOne(int step)
    {
        if (StepOneNum[step])
            StepOneNames[step].color = Color.red;
        if (getStepOneState())
        {
            stepOneScore = 1;
        }

        SetScore();
    }

    int step21;
    int step22;
    int step23;
    int step24;
    public void SetStepTwo(int step, bool canRed = false)
    {
        if (StepTwoNum[step] || canRed)
            StepTwoNames[step].color = Color.red;
        //else
        //    StepTwoNames[step].color = Color.black;
        switch (step)
        {
            case 0:
                step21 = 1;
                break;
            case 1:
                step22 = 1;
                break;
            case 2:
                step23 = 1;
                break;
            case 3:
                step24 = 1;
                break;

        }
        stepTwoScore = step21 + step22 + step23 + step24;
        if (getStepTwoState())
        {
            BigStepNames[0].color = Color.red;
            BigStepButtons[0].enabled = true;
            stepTwoScore = 4;
        }
        else
        {
            BigStepNames[0].color = Color.black;
            BigStepButtons[0].enabled = false;
        }
        SetScore();
    }

    public void SetStepThree(int step)
    {
        if (StepThreeNum[step])
            StepThreeNames[step].color = Color.red;
        //else
        //    StepThreeNames[step].color = Color.black;
        if (getStepThreeState())
        {
            BigStepNames[1].color = Color.red;
            BigStepButtons[1].enabled = true;
            stepThreeScore = 2;
        }
        else
        {
            BigStepNames[1].color = Color.black;
            BigStepButtons[1].enabled = false;
        }

        SetScore();
    }

    public void SetStepFour(int step)
    {
        if (StepFourNum[step])
            StepFourNames[step].color = Color.red;
        //else
        //    StepFourNames[step].color = Color.black;
        if (getStepFourState())
        {
            BigStepNames[2].color = Color.red;
            BigStepButtons[2].enabled = true;
            stepFourScore = 2;
        }
        else
        {
            BigStepNames[2].color = Color.black;
            BigStepButtons[2].enabled = false;
        }

        SetScore();
    }

    public void SetStepFive(int step)
    {
        if (StepFiveNum[step])
            StepFiveNames[step].color = Color.red;
        //else
        //    StepFiveNames[step].color = Color.black;
        if (getStepFiveState())
        {
            BigStepNames[3].color = Color.red;
            BigStepButtons[3].enabled = true;
            stepFiveScore = 1;
        }
        else
        {
            BigStepNames[3].color = Color.black;
            BigStepButtons[3].enabled = false;
        }
        SetScore();
    }

    public bool getStepOneState()
    {
        if (StepOneNum == null || StepOneNum.Length == 0) return false;
        for (int i = 0; i < StepOneNum.Length; i++)
        {
            if (!StepOneNum[i])
            {
                return false;
            }
        }
        return true;
    }

    public bool getStepTwoState()
    {
        if (StepTwoNum == null || StepTwoNum.Length == 0) return false;
        for (int i = 0; i < StepTwoNum.Length; i++)
        {
            if (!StepTwoNum[i])
            {
                return false;
            }
        }
        return true;
    }

    public bool getStepThreeState()
    {
        if (StepThreeNum == null || StepThreeNum.Length == 0) return false;
        for (int i = 0; i < StepThreeNum.Length; i++)
        {
            if (!StepThreeNum[i])
            {
                return false;
            }
        }
        return true;
    }

    public bool getStepFourState()
    {
        if (StepFourNum == null || StepFourNum.Length == 0) return false;
        for (int i = 0; i < StepFourNames.Length; i++)
        {
            if (!StepFourNum[i])
            {
                return false;
            }
        }
        return true;
    }

    public bool getStepFiveState()
    {
        if (StepFiveNum == null || StepFiveNum.Length == 0) return false;

        return StepFiveNum[0] && StepFiveNum[1];
    }

    public void ResetStep()
    {
        Destroy(self.gameObject);
        GameObject presentLevle = Instantiate(demo.gameObject);
        //调用IBaseScene上的OnStartSceneEnter方法
        presentLevle.GetComponent<IBaseScene>().OnStartSceneEnter();
        Beaker.m_FtNum = 0;
        RoundBottpmFlask.HaveStopper = false;
        RoundBottpmFlask.HaveWater = false;
        WaterStopClip.OpenJiaZi = true;
        // BigStepsManager.Instance.SetBigStepOne();
        // ResetScore();
        // ResetText();
    }

    private void LateUpdate()
    {

    }

    private void OnDestroy() {

    }
}
